﻿using IronPython.Runtime.Exceptions;
using Microsoft.Scripting;
using System;

namespace NFox.Pyeditor.Runtime
{
    public class BreakPoint : IEquatable<BreakPoint>
    {

        public string FileName { get; }

        public int Line { get; set; }

        public TraceBackFrame BackFrame { get; }

        public SourceSpan Span { get; }

        public bool AtEndLine
        {
            get { return Line == Span.End.Line; }
        }

        public BreakPoint(TraceBackFrame frame)
        {
            FileName = frame.f_code.co_filename;
            Line = (int)frame.f_lineno;
            Span = frame.f_code.Span;
            BackFrame = frame.f_back;
        }

        public BreakPoint(string filename, int line)
        {
            FileName = filename;
            Line = line;
        }

        public bool Equals(BreakPoint other)
        {
            return FileName.ToLower() == other.FileName.ToLower() && Line == other.Line; 
        }

        public bool IsNext(BreakPoint pt)
        {
            return FileName == pt.FileName && Span == pt.Span && Line != pt.Line;
        }

    }
}
